import 'package:flutter/material.dart';

class CustomTextField extends StatefulWidget {
  String icon;
  Color borderColor;
  Color backgroundColor;
  String hint;
  double width;
  double height=40.0;
  TextEditingController controller;
  double textSize;
  Color textColor;
  CustomTextField({this.icon,this.borderColor,this.hint,this.controller,this.width,this.height,this.backgroundColor,this.textSize,this.textColor});
  @override
  State<CustomTextField> createState() => _CustomTextFieldState();
}

class _CustomTextFieldState extends State<CustomTextField> {
  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return buildText();
  }

  Widget buildText(){
    if(widget.icon!=null){
      return  Container(
        height: widget.height,
        width: widget.width,
        child: TextField(
          controller: widget.controller,
          keyboardType: TextInputType.number,
          decoration: InputDecoration(
            prefixIcon: Container(
              width: 1,
              height: 1,
              padding:  const EdgeInsets.fromLTRB(15.0, 0, 15.0, 0),
              child: Center(child: Image.asset(widget.icon)),
            ),
            hintText:widget.hint,
            hintStyle: new TextStyle(color: Colors.grey),
            border: InputBorder.none,

          ),
          onChanged: (str) {
            setState(() {
//            _warning = "";
//            _phone = str;
            });
          },
          style: new TextStyle(
              fontSize: widget.textSize,
              color: widget.textColor
          ),
        ),
        decoration: BoxDecoration(borderRadius: BorderRadius.circular(10.0),
            color: widget.backgroundColor
        ),
      );
    }else{
      return  Container(
        height: widget.height,
        width: widget.width,
        child: TextField(
          controller: widget.controller,
          keyboardType: TextInputType.number,
          decoration: InputDecoration(

            hintText:widget.hint,
            hintStyle: new TextStyle(color: Colors.grey),
            border: InputBorder.none,

          ),
          onChanged: (str) {
            setState(() {
//            _warning = "";
//            _phone = str;
            });
          },
          style: new TextStyle(
              fontSize: widget.textSize,
              color: widget.textColor
          ),
        ),
        decoration: BoxDecoration(borderRadius: BorderRadius.circular(10.0),
            color: Colors.white
        ),
      );
    }
  }
}